package com.ruoyi.evalution.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.evalution.domain.LabEvalutionTopicTask;
import com.ruoyi.evalution.service.ILabEvalutionTopicTaskService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评测人员Controller
 * 
 * @author winner pan
 * @date 2022-08-03
 */
@RestController
@RequestMapping("/evalution/topicTask")
public class LabEvalutionTopicTaskController extends BaseController {
	@Autowired
	private ILabEvalutionTopicTaskService labEvalutionTopicTaskService;

	/**
	 * 查询评测人员列表
	 */
	@PreAuthorize("@ss.hasPermi('evalution:topicTask:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabEvalutionTopicTask labEvalutionTopicTask) {
		startPage();
		labEvalutionTopicTask.setUserName(SecurityUtils.getUsername());
		labEvalutionTopicTask.setScoreType(1);
		List<LabEvalutionTopicTask> list = labEvalutionTopicTaskService
				.selectLabEvalutionTopicTaskList(labEvalutionTopicTask);
		return getDataTable(list);
	}
	
	@PreAuthorize("@ss.hasPermi('evalution:topicResult:query')")
	@GetMapping("/academylist")
	public TableDataInfo acaddemylist(LabEvalutionTopicTask labEvalutionTopicTask) {
		startPage();
		labEvalutionTopicTask.setScoreType(2);
		List<LabEvalutionTopicTask> list = labEvalutionTopicTaskService
				.selectLabEvalutionTopicTaskList(labEvalutionTopicTask);
		return getDataTable(list);
	}

	/**
	 * 导出评测人员列表
	 */
	@PreAuthorize("@ss.hasPermi('evalution:topicTask:export')")
	@Log(title = "评测人员", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(LabEvalutionTopicTask labEvalutionTopicTask) {
		List<LabEvalutionTopicTask> list = labEvalutionTopicTaskService
				.selectLabEvalutionTopicTaskList(labEvalutionTopicTask);
		ExcelUtil<LabEvalutionTopicTask> util = new ExcelUtil<LabEvalutionTopicTask>(LabEvalutionTopicTask.class);
		return util.exportExcel(list, "topicTask");
	}

	/**
	 * 获取评测人员详细信息
	 */
	@PreAuthorize("@ss.hasPermi('evalution:topicTask:query')")
	@GetMapping(value = "/{evalutionTaskId}")
	public AjaxResult getInfo(@PathVariable("evalutionTaskId") Long evalutionTaskId) {
		return AjaxResult.success(labEvalutionTopicTaskService.selectLabEvalutionTopicTaskById(evalutionTaskId));
	}

	/**
	 * 新增评测人员
	 */
	@PreAuthorize("@ss.hasPermi('evalution:topicTask:edit')")
	@Log(title = "评测人员", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabEvalutionTopicTask labEvalutionTopicTask) {
		return toAjax(labEvalutionTopicTaskService.insertLabEvalutionTopicTask(labEvalutionTopicTask));
	}

	/**
	 * 修改评测人员
	 */
	@PreAuthorize("@ss.hasPermi('evalution:topicTask:edit')")
	@Log(title = "评测人员", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabEvalutionTopicTask labEvalutionTopicTask) {
		return toAjax(labEvalutionTopicTaskService.updateLabEvalutionTopicTask(labEvalutionTopicTask));
	}

	/**
	 * 删除评测人员
	 */
	@PreAuthorize("@ss.hasPermi('evalution:topicTask:edit')")
	@Log(title = "评测人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{evalutionTaskIds}")
	public AjaxResult remove(@PathVariable Long[] evalutionTaskIds) {
		return toAjax(labEvalutionTopicTaskService.deleteLabEvalutionTopicTaskByIds(evalutionTaskIds));
	}
}
